package com.sailing.xjpb.web.base.utils;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sailing.xjpb.common.web.WebUtils;
import org.springframework.web.context.request.NativeWebRequest;

import javax.servlet.http.HttpServletRequest;

/**
 * spring request通用工具类
 * add by YaoWei since 2023-04-11
 */
public class WebRequestUtils {

    private WebRequestUtils() {

    }

    /**
     * 从请求对象中获取请求参数内容
     *
     * @param webRequest 请求对象
     * @return 请求体内容
     */
    public static StringBuilder getRequestBody(NativeWebRequest webRequest) {
        HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
        return WebUtils.getRequestBody(request);
    }

    /**
     * 从请求对象中获取请求参数内容
     *
     * @param webRequest 请求对象
     * @return 请求体内容
     */
    public static ObjectNode getJsonRequestBody(NativeWebRequest webRequest) {
        HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
        return WebUtils.getJsonRequestBody(request);
    }

}
